package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoAssociation;
import com.muyu.danmo.service.IDanmoAssociationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 协会Controller
 *
 * @author yangle
 * @date 2024-09-27
 */
@RestController
@RequestMapping("/association")
public class DanmoAssociationController extends BaseController
{
    @Autowired
    private IDanmoAssociationService danmoAssociationService;

    /**
     * 查询协会列表
     */
//    @RequiresPermissions("system:association:list")
    @PostMapping("/list")
    public Result<List<DanmoAssociation>> list(@RequestBody DanmoAssociation danmoAssociation)
    {
        List<DanmoAssociation> list = danmoAssociationService.selectDanmoAssociationList(danmoAssociation);
        return Result.success(list);
    }

    /**
     * 导出协会列表
     */
//    @RequiresPermissions("system:association:export")
    @Log(title = "协会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoAssociation danmoAssociation)
    {
        List<DanmoAssociation> list = danmoAssociationService.selectDanmoAssociationList(danmoAssociation);
        ExcelUtil<DanmoAssociation> util = new ExcelUtil<DanmoAssociation>(DanmoAssociation.class);
        util.exportExcel(response, list, "协会数据");
    }

    /**
     * 获取协会详细信息
     */
//    @RequiresPermissions("system:association:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoAssociationService.selectDanmoAssociationById(id));
    }

    /**
     * 新增协会
     */
//    @RequiresPermissions("system:association:add")
    @Log(title = "协会", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoAssociation danmoAssociation)
    {
        return toAjax(danmoAssociationService.insertDanmoAssociation(danmoAssociation));
    }

    /**
     * 修改协会
     */
//    @RequiresPermissions("system:association:edit")
    @Log(title = "协会", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoAssociation danmoAssociation)
    {
        return toAjax(danmoAssociationService.updateDanmoAssociation(danmoAssociation));
    }

    /**
     * 删除协会
     */
//    @RequiresPermissions("system:association:remove")
    @Log(title = "协会", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoAssociationService.deleteDanmoAssociationByIds(ids));
    }
}
